package com.ruoyi.oa.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.oa.domain.OaDocNum;
import com.ruoyi.oa.service.IOaDocNumService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 单据编号Controller
 * 
 * @author ruoyi
 * @date 2021-11-12
 */
@RestController
@RequestMapping("/docNum")
public class OaDocNumController extends BaseController
{
    @Autowired
    private IOaDocNumService oaDocNumService;

    /**
     * 查询单据编号列表
     */
    @PreAuthorize(hasPermi = "oa:docNum:list")
    @GetMapping("/list")
    public TableDataInfo list(OaDocNum oaDocNum)
    {
        startPage();
        List<OaDocNum> list = oaDocNumService.selectOaDocNumList(oaDocNum);
        return getDataTable(list);
    }

    /**
     * 导出单据编号列表
     */
    @PreAuthorize(hasPermi = "oa:docNum:export")
    @Log(title = "单据编号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaDocNum oaDocNum) throws IOException
    {
        List<OaDocNum> list = oaDocNumService.selectOaDocNumList(oaDocNum);
        ExcelUtil<OaDocNum> util = new ExcelUtil<OaDocNum>(OaDocNum.class);
        util.exportExcel(response, list, "单据编号数据");
    }

    /**
     * 获取单据编号详细信息
     */
    @PreAuthorize(hasPermi = "oa:docNum:query")
    @GetMapping(value = "/{docNum}")
    public AjaxResult getInfo(@PathVariable("docNum") Long docNum)
    {
        return AjaxResult.success(oaDocNumService.selectOaDocNumByDocNum(docNum));
    }

    /**
     * 新增单据编号
     */
    @PreAuthorize(hasPermi = "oa:docNum:add")
    @Log(title = "单据编号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaDocNum oaDocNum)
    {
        int i = oaDocNumService.insertOaDocNum(oaDocNum);
        return toAjax(i);
    }

    @PostMapping(value = "/new")
    public AjaxResult newDocNum(@RequestBody OaDocNum oaDocNum)
    {
        return AjaxResult.success(oaDocNumService.newDocNum(oaDocNum));
    }

    /**
     * 修改单据编号
     */
    @PreAuthorize(hasPermi = "oa:docNum:edit")
    @Log(title = "单据编号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaDocNum oaDocNum)
    {
        return toAjax(oaDocNumService.updateOaDocNum(oaDocNum));
    }

    /**
     * 删除单据编号
     */
    @PreAuthorize(hasPermi = "oa:docNum:remove")
    @Log(title = "单据编号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{docNums}")
    public AjaxResult remove(@PathVariable Long[] docNums)
    {
        return toAjax(oaDocNumService.deleteOaDocNumByDocNums(docNums));
    }
}
